package com.lanchetech.user.controller;

import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.InvoiceApplyResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.InvoiceApplyVO;
import com.lanchetech.bean.vo.InvoiceCountVO;
import com.lanchetech.entity.InvoiceAccount;
import com.lanchetech.entity.InvoiceApply;
import com.lanchetech.entity.User;
import com.lanchetech.user.service.InvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "发票接口", tags = "发票接口")
@RequestMapping("/api/invoice/")
@RestController
public class InvoiceController {

    @Autowired
    InvoiceService invoiceService;

    @ApiOperation("添加开票账号")
    @PostMapping("/editInvoiceAccount")
    public BaseResp editInvoiceAccount(@AuthenticationPrincipal User user, @RequestBody InvoiceAccount invoiceAccount) {
        return invoiceService.editInvoiceAccount(user, invoiceAccount);
    }

    @ApiOperation("删除开票账号")
    @GetMapping("/deleteInvoiceAccount")
    public BaseResp deleteInvoiceAccount(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return invoiceService.deleteInvoiceAccount(user, id);
    }

    @ApiOperation("申请开发票")
    @PostMapping("/editInvoiceApply")
    public BaseResp editInvoiceApply(@AuthenticationPrincipal User user, @RequestBody InvoiceApply invoiceApply) {
        return invoiceService.editInvoiceApply(user, invoiceApply);
    }

    @ApiOperation("获取开票账号列表")
    @GetMapping("/getInvoiceAccountList")
    public ResultData<List<InvoiceAccount>> getInvoiceAccountList(@AuthenticationPrincipal User user) {
        return invoiceService.getInvoiceAccountList(user);
    }

    @ApiOperation("获取开票账号详情")
    @GetMapping("/getInvoiceAccountDetail")
    public ResultData<InvoiceAccount> getInvoiceAccountDetail(@AuthenticationPrincipal User user, @RequestParam("id") Long id) {
        return invoiceService.getInvoiceAccountDetail(user, id);
    }


    @ApiOperation("获取开票申请详情")
    @GetMapping("/getInvoiceApplyDetail")
    public ResultData<InvoiceApplyResp> getInvoiceApplyDetail(@AuthenticationPrincipal User user, @RequestParam("orderId") Long orderId, @RequestParam(value = "type", required = false) Byte type) {
        return invoiceService.getInvoiceApplyDetail(user, orderId, type);
    }

    @ApiOperation("获取发票申请分页")
    @PostMapping("/getInvoiceApplyPage")
    public ResultData<BasePageResp<InvoiceApplyVO>> getInvoiceApplyPage(@RequestBody PageReq req) {
        return invoiceService.getInvoiceApplyPage(req);
    }

    @ApiOperation("统计总的开票次数和金额")
    @GetMapping("/countInvoice")
    public ResultData<InvoiceCountVO> countInvoice(@AuthenticationPrincipal User user) {
        return invoiceService.countInvoice(user);
    }


}
